package com.thread.sychronized;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author wangyingjie
 * @date
 * @remark
 */
public class CallableDemo {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CallableThread callableThread = new CallableThread();
        FutureTask<Integer> futureTask = new FutureTask<Integer>(callableThread);
        Thread t = new Thread(futureTask, "子线程");
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+"执行了"+i);
            if (i==20){
                t.start();
                System.out.println("子线程返回值"+futureTask.get());//调用get()会使主线程阻塞，直到子线程运行完
            }
        }
    }
}
